#ifndef _CDROM_H
#define _CDROM_H

#define BR_DESC		0
#define PVD_DESC	1
#define SVD_DESC	2
#define VPD_DESC	3
#define END_DESC	255

#define PRIMARY_DESC_BLOCK 0x00000010

struct iso_date{
	char year[4];
	char month[2];
	char day[2];
	char hour[2];
	char minute[2];
	char second[2];
	char second1[2]; // 10MS
	unsigned char offset;
}__attribute__((packed));

struct iso_primary_descriptor{
	unsigned char type;
	unsigned char id[5];
	unsigned char version;

	unsigned char unused1;
	unsigned char system_id[32];
	unsigned char volume_id[32];
	unsigned char unused2[8];
	unsigned long volume_space_size;
	unsigned long volume_space_size1;
	unsigned char unused3[32];
	unsigned short volume_set_size;
	unsigned short volume_set_size1;
	unsigned short volume_sequence_number;
	unsigned short volume_sequence_number1;
	unsigned short logical_block_size;
	unsigned short logical_block_size1;
	unsigned long path_table_size;
	unsigned long path_table_size1;
	unsigned long type_l_path_table;
	unsigned long opt_type_l_path_table;
	unsigned long type_m_path_table;
	unsigned long opt_type_m_path_table;
	unsigned char root_directory_record[34];
	unsigned char volume_set_id[128];
	unsigned char publisher_id[128];
	unsigned char preparer_id[128];
	unsigned char application_id[128];
	unsigned char copyright_file_id[37];
	unsigned char abstract_file_id[37];
	unsigned char bibliographic_file_id[37];
	struct iso_date creation_date;
	struct iso_date modification_date;
	struct iso_date expiration_date;
	struct iso_date effective_date;
	unsigned char file_struct_version;
	unsigned char unused4;
	unsigned char application_data[512];
	unsigned char unused5[653];
}__attribute__((packed));

struct iso_path_table{
	unsigned char length;
	unsigned char unused1;
	unsigned char directory_sector_number[4];
	unsigned char parent_directory_record_number[2];
	unsigned char name[0];
}__attribute__((packed));

#define ISO_HIDDEN(x)	(x & 0x01)
#define ISO_ISDIR(x)	(x & 0x02)
#define ISO_ASSOC(x)	(x & 0x04)
#define ISO_RECORD(x)	(x & 0x08)
#define ISO_PERM(x)	(x & 0x10)
#define ISO_NFINAL(x)	(x & 0x80)

struct iso_directory_record{
	unsigned char length;
	unsigned char ext_attr_length;
	unsigned long first_sector;
	unsigned long first_sector1;
	unsigned long size;
	unsigned long size1;
	unsigned char date[7];
	unsigned char flags;
	unsigned char file_unit_size;
	unsigned char interleave;
	unsigned short volume_sequence_number;
	unsigned short volume_sequence_number1;
	unsigned char name_len;
	unsigned char name[0];
}__attribute__((packed));

struct iso9660_super_block{
	unsigned short lbs; // logical block size
	unsigned long vss; //volume space size
	unsigned long sum;
	unsigned long path_table;
	unsigned long path_table_size;
	struct iso_directory_record root_directory_record;
};

extern BOOLEAN ide_cdrom_open(dev_t minor, void * data);

#endif
